<?php
class SettingsController extends AppController{
        var $name = 'Settings';
        
		function beforeRender(){
			parent::beforeRender();
			$this->set('menu_parent', 'Settings');			
			$this->set('menu_subactive', 'General');		
		}        

        function admin_index() {

                if (isset($this->passedArgs['keywords']) && $this->passedArgs['keywords']) {
                        $this->paginate['conditions'][]['Setting.name'] = 'LIKE %'.$this->passedArgs['keywords'].'%';
                        $this->paginate['conditions'][]['Setting.category'] = 'LIKE %'.$this->passedArgs['keywords'].'%';
                        $this->paginate['conditions'][]['Setting.setting'] = 'LIKE %'.$this->passedArgs['keywords'].'%';
                        $this->data['Search']['keywords'] = $this->passedArgs['keywords'];
                }
                if (isset($this->passedArgs['category']) && $this->passedArgs['category']) {
                        $this->paginate['conditions'][]['Setting.category'] = $this->passedArgs['category'];
                        $this->data['Search']['category'] = $this->passedArgs['category'];
                }
                $settings = $this->paginate();
                $this->set('settings', $settings);              
        }


		function admin_view($id = null) {
			$this->Redirect->idEmpty($id, array('action' => 'index'));
			$this->set('setting', $this->Setting->read(null, $id));
		}
        
        function admin_add() {
                $this->admin_form();
        }
        function admin_edit($id = null) {
				$this->Redirect->idEmpty($id, array('action' => 'index'));
                $this->admin_form($id);
        }
       
		function admin_delete($id = null) {
			$this->Redirect->idEmpty($id, array('action' => 'index'));
			if ($this->Setting->del($id)) {
				$this->Redirect->flashSuccess('Setting Deleted.', array('action' => 'index'));
			}
			$this->autoRender = false;
		}        
		
        function admin_form($id = null) {
                if (!empty($this->data)) {
                        // save the data                       
                        if ($this->Setting->save($this->data)) {
								$this->Redirect->flashSuccess('Setting Saved.', array('action' => 'view', $this->Setting->id));
                        } else {
								$this->Redirect->flashWarning('Setting could not be saved. Please try again.');	
                        }
                }
                if (empty($this->data)) {
                        $this->data = $this->Setting->read(null, $id);
                }
        }
        
	
	function admin_search() {
		$this->Search->doSearch($this,$this->passedArgs);	
	}

	function admin_dataSearch() {
		$this->Search->redirectDataSearch($this,$this->data);
	}	    
       
}